package com.wzc.pet.service.impl;

import com.wzc.basic.service.impl.BaseServiceImpl;
import com.wzc.pet.domain.Pet;
import com.wzc.pet.domain.PetDetail;
import com.wzc.pet.mapper.PetDetailMapper;
import com.wzc.pet.mapper.PetMapper;
import com.wzc.pet.service.IPetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PetServiceImpl extends BaseServiceImpl<Pet> implements IPetService {

    @Autowired
    private PetMapper petMapper;

    @Autowired
    private PetDetailMapper petDetailMapper;

    @Override
    public void save(Pet pet) {
        // 先存pet,返回自增的主键
        petMapper.save(pet);
        // 再存petDetail
        PetDetail petDetail = pet.getPetDetail();
        petDetail.setPet_id(pet.getId());
        petDetailMapper.save(petDetail);
    }


    @Override
    public void update(Pet pet) {
        // 修改时不分 先后
        petMapper.update(pet);
        petDetailMapper.update(pet.getPetDetail());
    }

    /**
     * 上架
     * @param ids
     */
    @Override
    public void offSale(List<Long> ids) {
        /**
         * 改状态：直接在sql语句中将 statef 赋值
         * 改上架时间：创建一个当前时间，数据库修改
         */
        Date date = new Date();
        petMapper.onSale(ids,date);
    }

    /**
     * 下架
     * @param ids
     */
    @Override
    public void onSale(List<Long> ids) {
        /**
         * 改状态：直接在sql语句中将 statef 赋值
         * 改下架时间：创建一个当前时间，数据库修改
         */
        Date date = new Date();
        petMapper.offSale(ids,date);
    }
}
